<?php
/**
 * $Id: ohabolana.php 93 2010-07-27 09:36:19Z heriniaina.eugene $
 * $Revision$
 * $Author$
 * $Date$
 *
 * Copyright (c) 2006 Hery Eugene <hery@serasera.org>
 *
 * Full GPL License: <http://www.gnu.org/licenses/gpl.txt>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 */
 


class ohabolana extends module
{

	public $name = "Ohabolana Module";
	public $author = "Hery";
	public $version = "0.9";


	function init()
	{
		$ini = new ini('data/vonjy.ini');
		$ini->setIniVal("#serasera", "!ohabolana", "Mampiseho ohabolana avy amin'ny ohabolana.org");
		$ini->writeIni();
		require_once("libraries/xml.php");
	}
	
	function reply($line, $args)
	{
		/*
		if(!$user = $this->getModule("user")->loggedin($line))
		{
			$this->getModule("user")->printError($line);
			return;
		}
		*/
		
		if ($line['to'] == $this->ircClass->getNick())
		{
			$to = $line['fromNick'];
		}
		else
		{
			$to = $line['to'];
		}
		
		if ($args['nargs'] > 0)
		{
			$tadiavo = $args['query'];
		}
		
		$query = "tadiavo=" . urlencode($tadiavo);
		$request = "http://ohabolana.org/ohabolana/rest/get/plain";
		$session = curl_init($request);
		// Tell curl to use HTTP POST
		curl_setopt ($session, CURLOPT_POST, true); 
		// Tell curl that this is the body of the POST
		curl_setopt ($session, CURLOPT_POSTFIELDS, $query); 
		// Tell curl not to return headers, but do return the response
		curl_setopt($session, CURLOPT_HEADER, false); 
		curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
		$response = curl_exec($session); 
		curl_close($session);
			
		if($response) {
			$this->ircClass->privMsg($to, $response);
			return;
		}
		
		return ;
	}

}
?>